const mongoose = require('mongoose');

const postSchema = new mongoose.Schema({
  title: {
    type: String,
    required: [true, '标题不能为空']
  },
  content: {
    type: String,
    required: [true, '内容不能为空']
  },
  category: {
    type: String,
    required: [true, '分类不能为空'] // 分类：如通知、话题、活动、市场、作品等
  },
  author: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: [true, '发布人不能为空']
  },
  cover: {
    type: String
  }, // 封面图片/视频URL
  mediaType: {
    type: String,
    enum: ['image', 'video', 'text'],
    default: 'image'
  }, // 媒体类型
  tags: [String],
  views: {
    type: Number,
    default: 0
  },
  likes: {
    type: Number,
    default: 0
  },
  likedBy: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  }],
  comments: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Comment'
  }],
  file: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'File',
    default: null
  }, // 附件文件（如文档）
  createdAt: {
    type: Date,
    default: Date.now
  },
  updatedAt: {
    type: Date,
    default: Date.now
  }
});

module.exports = mongoose.model('Post', postSchema);